package xkp.lesson.ui;

import xkp.lesson.utils.ReadJobData;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.sql.SQLException;

public class ReadJobUi extends JFrame {
    public ReadJobUi(){
        //窗体大小
        this.setSize(700,100);
        //设置窗体大小不可改变
        this.setResizable(false);

        //自动隐藏并释放该窗体
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        //相对屏幕居中
        this.setLocationRelativeTo(null);
        //窗体名字
        this.setTitle("爬取数据");

        //流式布局
        FlowLayout flow = new FlowLayout();
        this.setLayout(flow);

        JLabel jLabelJob = new JLabel("职位");
        jLabelJob.setFont(new Font("黑体", Font.BOLD, 24));
        this.add(jLabelJob);
        JTextField jobText = new JTextField();
        jobText.setPreferredSize(new Dimension(240,40));
        this.add(jobText);

        JLabel jLabelCity = new JLabel("城市");
        jLabelCity.setFont(new Font("黑体", Font.BOLD, 24));
        this.add(jLabelCity);
        JTextField cityText = new JTextField("");
        cityText.setPreferredSize(new Dimension(240,40));
        this.add(cityText);
        JButton beginBtn = new JButton("开始");
        beginBtn.setFont(new Font("黑体", Font.BOLD, 24));
        this.add(beginBtn);
        beginBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String city = cityText.getText().trim();
                String kw = jobText.getText().trim();
                try {
                    ReadJobData.readData(city,kw,1);
                } catch (IOException e1) {
                    e1.printStackTrace();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
        });
        this.setVisible(true);

    }
}
